<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>参数设置</title>
<%@ include file="../../../common/admin_taglib.jsp" %>
<script type="text/javascript">
function editItem(id) {
	$("#nlab_" + id).hide();
	$("#name_" + id).show();
	$("#vlab_" + id).hide();
	$("#sysValue_" + id).show();
	$("#editBtn_" + id).hide();
	$("#saveBtn_" + id).show();
	$("#cancelBtn_" + id).show();
}
function cancelEdit(id) {
	$("#nlab_" + id).show();
	$("#name_" + id).hide();
	$("#vlab_" + id).show();
	$("#sysValue_" + id).hide();
	$("#editBtn_" + id).show();
	$("#saveBtn_" + id).hide();
	$("#cancelBtn_" + id).hide();
}
function saveItem(id) {
	var name = $("#name_" + id).val();
	var value = $("#sysValue_" + id).val();
	if (name == null || name == "") {
		$("#name_" + id).css("border-color", "red");
		return;
	} else {
		$("#name_" + id).css("border-color", "");
	}
	if (value == null || value == "") {
		$("#sysValue_" + id).css("border-color", "red");
		return;
	} else {
		$("#sysValue_" + id).css("border-color", "");
	}
	$.post("${ctx}/admin/sysconst/update", {
		"id" : id,
		"name" : name,
		"sysValue" : value
	}, function(result){
		if (result) {
			$("#nlab_" + id).text(name);
			$("#vlab_" + id).text(value);
			cancelEdit(id);
		} else {
			alert("保存失败...");
		}
	});
}
</script>
</head>
<body>
<h1 class="page-title">Shop4j 管理中心</h1>
<ul class="breadcrumb">
	 <li><a href="${ctx}/admin/main">管理中心</a><span class="divider">/</span></li>
     <li class="active">订单列表</li>
</ul>

<div class="row-fluid">
	<div class="btn-toolbar">
	    <a class="btn btn-primary" href="#"><i class="icon-plus"></i>添加参数</a>
	  	<div class="btn-group"></div>
	</div>
	<div class="block">
		<div class="block-heading">
            <span class="block-icon pull-right">
                <a href="#widget2container" data-toggle="collapse">
                	<i class="icon-chevron-down"></i>
                </a>
            </span>
            <a>参数查询</a>
        </div>
        <div id="widget2container" class="block-body collapse in">
        	<form:form id="search_form" cssClass="form-horizontal" method="post" commandName="constant">
	        	<table width="100%">
	        		<tr>
	        			<td>参数CODE</td>
	        			<td>
	        				<form:input path="code" cssClass="input-xlarge" placeholder="请输入文字..."/>
	        			</td>
	        			<td>参数名称</td>
	        			<td>
	        				<form:input path="name" cssClass="input-xlarge" placeholder="请输入文字..."/>
	        			</td>
	        			<td align="right">
	        				<button type="submit" class="btn btn-info">
	        					<i class="icon-search"></i>
	        					搜索
	        				</button>
	        			</td>
	        		</tr>
	        	</table>
	        </form:form>
        </div>
    </div>
	
	<div class="well">
		<table class="table">
			<thead>
		    	<tr>
		    		<th width="10%">#ID</th>
		    		<th width="15%">CODE</th>
		    		<th width="30%">参数名称</th>
		    		<th width="30%">参数值</th>
		    		<th width="15%">操作</th>
		    	</tr>
		    </thead>
		    <tbody>
		     	<c:forEach items="${page.entities}" var="c">
		    	<tr>
		    		<td>${c.id}</td>
		    		<td>${c.code}</td>
		    		<td>
		    			<label id="nlab_${c.id}">${c.name}</label>
		    			<input id="name_${c.id}" name="name" type="text" class="input-large" style="display:none;" value="${c.name}"/>
		    		</td>
		    		<td>
		    			<label id="vlab_${c.id}">${c.sysValue}</label>
		    			<input id="sysValue_${c.id}" name="sysValue" type="text" class="input-large" style="display:none;" value="${c.sysValue}"/>
		    		</td>
		    		<td>
		    			<a id="editBtn_${c.id}" class="btn btn-small" href="javascript:editItem(${c.id});">编辑</a>
		    			<a id="saveBtn_${c.id}" class="btn btn-small" href="javascript:saveItem(${c.id});" style="display:none;">保存</a>
		    			<a id="cancelBtn_${c.id}" class="btn btn-small" href="javascript:cancelEdit(${c.id});" style="display:none;">取消</a>
		    		</td>
		    	</tr>
		    	</c:forEach>
		    </tbody>
		</table>
	</div>
	<dd:pagination formId="search_form" count="${page.count}" page="${page.page}" curpage="${page.curpage}"></dd:pagination>
</div>
</body>
</html>